package com.gqr.threadsafe;

import javax.sound.midi.Soundbank;

/**
 * Copyright (C), 2020-2024,gqr
 * FileName:MultiThreadsError4
 * author:guqingrong
 * Date:2024-04-27 10:39
 * Description:初始化未完毕,就this赋值 逸出
 * History:
 * <author>    <time>    <version>    <desc>
 * 作者姓名     修改时间     版本号        描述
 */
public class MultiThreadsError4 {
    static Point point;

    public static void main(String[] args) throws InterruptedException {
        new PointMaker().start();
        // 发布时间不同 初始化的值不同 这是不对的
//        Thread.sleep(10);
        Thread.sleep(105);
        if(point!=null){
            System.out.println(point);
        }
    }
}

class Point{
    private final int x;
    private final int y;

    public Point(int x, int y) throws InterruptedException {
        this.x = x;
        MultiThreadsError4.point = this;
        Thread.sleep(100);
        this.y = y;
    }

    @Override
    public String toString() {
        return x+","+y;
    }
}
class PointMaker extends Thread{
    @Override
    public void run(){
        try {
            new Point(1,1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
